﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Moe_v0._1
{
    class MoeAI : IChatterBotBehaviour
    {
        // Singleton pattern:
        private static MoeAI _moe = null;
        protected MoeAI() {}
        public static MoeAI Instance()
        {
            if (_moe == null)
            {
                _moe = new MoeAI();
            }
            Debug.Assert(_moe != null);
            return _moe;
        }

        // Implementation for IChatterBotBehaviour.
        private string _question = "";
        private string _answer = "Pardon?";
        private string _instruction = "";
        private EnPrefixTreeModel _model = EnPrefixTreeModel.Instance();

        public void RecieveQuestion(string input)
        {
            _question = input;
            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("RecieveQuestion: " + _question);
            }
        }
        public string AnswerQuestion()
        {
            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("AnswerQuestion: " + _answer);
            }

            // TODO: process the _question and select answer from database to fit _answer.
            // First of all, we tokenize the _question.
            StructuredSentence tokenizedSentence = EnSegmentor.TokenizeSentence(_question);

            // Secondly, get possible answer with the help of a model.
            _answer = _model.ProcessTokenizedSentence(tokenizedSentence);

            return _answer;
        }
        public void RecieveInstruction(string input)
        {
            _instruction = input;
            if (MoeDebugger.IsDebugging)
            {
                MoeDebugger.AddDebugInfo("RecieveInstruction: " + _instruction);
            }
        }
        public void ComplieInstruction()
        {
            // TODO: process _instruction and compile some command.
        }
    }
}
